<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/1
 * Time: 13:20
 */

namespace app\api\controller;


use app\common\controller\Api;
use app\common\model\Activities as Model;
use think\Request;

class Activities extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function lists(Model $model)
    {
        $now = time();
        $activities = $model->where('switch',1)
            ->whereTime('publishtime','<',$now)
            ->whereTime('endtime','>',$now)
            ->field('id,title,image,publishtime,endtime')
            ->order('weigh','desc')->select();
        $this->success('成功',$activities);
    }

    public function detail(Request $request)
    {
        $id = $request->get('id');
        if( !$id ){
            $this->error('未找到记录');
        }
        $activity = Model::where('id',$id)->field('id,title,image,content,publishtime,endtime')->find();
        $this->success('成功',$activity);
    }
}